<?php


function getLoggedInAsLine(){
    if (!isset($_SESSION)) {
        session_start();
    }
    $username = $_SESSION['username'];
    $realname = getPersonNameStringFromID(getPersonIDFromUsername($username));
    $role = $_SESSION['role'];
    $output = "";
    //toggle button used for testing
    //$output .= getFormLinePost('roleForm', 'mainPage.php?request=login&action=toggleUserRole');    
    //$output .= getFormInputElement('submit', 'submit', NULL, "Toggle");
    $output .= 'Username: <i>'.$username.'</i> ('.$realname.') <br> Role: '.$role.'<br>Version: 1.0.2<br></form>';
    return $output;
}

function toggleRole(){
    if (!isset($_SESSION)) {
        session_start();
    }
    $role = $_SESSION['role'];
    if(strcmp($role, "pi")===0){
        $_SESSION['role'] = "pireviewer";  
        $_SESSION['username'] = "pireviewer";  
    }
    else{
        $_SESSION['role'] = "pi";
        $_SESSION['username'] = "nstevens";
    }
}
function isTestMode(){
    if (!isset($_SESSION)) {
        session_start();
    }
    if(strcmp($_SESSION['testMode'],"true")===0){
        return true;
    }
    else{
        return false;
    }
}

function isPI(){
    if(strcmp(getUserRole(), "pi")===0){
        return true;
    }
    else{
        return false;
    }
}

function getUserRole(){
    if (!isset($_SESSION)) {
        session_start();
    }
    return $_SESSION['role'];
}

function getCurrentUser(){
    if (!isset($_SESSION)) {
        session_start();
    }
    return $_SESSION['username'];
}

function processSortChange($newSortField, $type) {

    if (strcmp($type, "project") === 0) {
        //set the sort field
        $_SESSION['projectSortField'] = $newSortField;

        //if the order is not set switch to desc since asc is the default
        if (!isset($_SESSION['projectSortOrder'])) {
            $_SESSION['projectSortOrder'] = "DESC";
            //echo 'Setting sortOrder to DESC <br>';
        } else {
            //toggle the sort order
            if (strcmp($_SESSION['projectSortOrder'], "ASC") === 0) {
                $_SESSION['projectSortOrder'] = "DESC";
                //echo 'Toggling sortOrder to DESC <br>';
            } else {
                $_SESSION['projectSortOrder'] = "ASC";
                //echo 'Toggling sortOrder to ASC <br>';
            }
        }
        //echo "order: " . $_SESSION['projectSortOrder'] . ' Field: ' . $_SESSION['projectSortField'] . '<br>';
    }
    else if (strcmp($type, "task") == 0) {
        //set the sort field
        $_SESSION['taskSortField'] = $newSortField;

        //if the order is not set switch to desc since asc is the default
        if (!isset($_SESSION['taskSortOrder'])) {
            $_SESSION['taskSortOrder'] = "DESC";
            //echo 'Setting sortOrder to DESC <br>';
        } else {
            //toggle the sort order
            if (strcmp($_SESSION['taskSortOrder'], "ASC") == 0) {
                $_SESSION['taskSortOrder'] = "DESC";
                //echo 'Toggling sortOrder to DESC <br>';
            } else {
                $_SESSION['taskSortOrder'] = "ASC";
               // echo 'Toggling sortOrder to ASC <br>';
            }
        }
        //echo "order: " . $_SESSION['taskSortOrder'] . ' Field: ' . $_SESSION['taskSortField'] . '<br>';
    }
    else if (strcmp($type, "req") == 0) {
        //set the sort field
        $_SESSION['reqSortField'] = $newSortField;

        //if the order is not set switch to desc since asc is the default
        if (!isset($_SESSION['reqSortOrder'])) {
            $_SESSION['reqSortOrder'] = "DESC";
            //echo 'Setting sortOrder to DESC <br>';
        } else {
            //toggle the sort order
            if (strcmp($_SESSION['reqSortOrder'], "ASC") == 0) {
                $_SESSION['reqSortOrder'] = "DESC";
                //echo 'Toggling sortOrder to DESC <br>';
            } else {
                $_SESSION['reqSortOrder'] = "ASC";
                //echo 'Toggling sortOrder to ASC <br>';
            }
        }
        //echo "order: " . $_SESSION['reqSortOrder'] . ' Field: ' . $_SESSION['reqSortField'] . '<br>';
    }
     else if (strcmp($type, "contract") == 0) {
        //set the sort field
        $_SESSION['contractSortField'] = $newSortField;

        //if the order is not set switch to desc since asc is the default
        if (!isset($_SESSION['contractSortOrder'])) {
            $_SESSION['contractSortOrder'] = "DESC";
            //echo 'Setting sortOrder to DESC <br>';
        } else {
            //toggle the sort order
            if (strcmp($_SESSION['contractSortOrder'], "ASC") == 0) {
                $_SESSION['contractSortOrder'] = "DESC";
                //echo 'Toggling sortOrder to DESC <br>';
            } else {
                $_SESSION['contractSortOrder'] = "ASC";
                //echo 'Toggling sortOrder to ASC <br>';
            }
        }
        //echo "order: " . $_SESSION['contractSortOrder'] . ' Field: ' . $_SESSION['contractSortField'] . '<br>';
    }
     else if (strcmp($type, "nonLaborCost") == 0) {
        //set the sort field
        $_SESSION['nonLaborCostSortField'] = $newSortField;

        //if the order is not set switch to desc since asc is the default
        if (!isset($_SESSION['nonLaborCostSortOrder'])) {
            $_SESSION['nonLaborCostSortOrder'] = "DESC";
            //echo 'Setting sortOrder to DESC <br>';
        } else {
            //toggle the sort order
            if (strcmp($_SESSION['nonLaborCostSortOrder'], "ASC") == 0) {
                $_SESSION['nonLaborCostSortOrder'] = "DESC";
                //echo 'Toggling sortOrder to DESC <br>';
            } else {
                $_SESSION['nonLaborCostSortOrder'] = "ASC";
                //echo 'Toggling sortOrder to ASC <br>';
            }
        }
        //echo "order: " . $_SESSION['nonLaborCostSortOrder'] . ' Field: ' . $_SESSION['nonLaborCostSortField'] . '<br>';
    }
    //getAllProjects();
}

?>
